/********************************************************************/
/*  Copyright (C) School of Software Engineering of USTC, 2012                               
/*                                                                                                                       
/*  FILE NAME: list.h                                                                                          
/*  PRINCIPAL AUTHOR: SA12226114(Xin Zhu), SA12226139(Dan Shu)                    
/*  SUBSYSTEM NAME:                                                                                     
/*  MODULE NAME: list                                                                                    
/*  LANGUAGE: C                                                                                                 
/*  TARGET ENVIRONMENT: Linux                                                                          
/*  DATE OF FIRST RELEASE: 2012-12-20                                                             
/*  DESCRIPTION: Impement of Abstract Interface for Tokyo Cabinet DB API              
/********************************************************************/


struct list_head 
{
    struct list_head *next, *prev;
}list_head_t;

#define LIST_HEAD_INIT(name) { &(name), &(name) }

#define LIST_HEAD(name) \
    struct list_head name = LIST_HEAD_INIT(name)

#define INIT_LIST_HEAD(ptr) do { \
    (ptr)->next = (ptr); (ptr)->prev = (ptr); \
} while (0)

 
/*****************************************************************
Function Name: list_entry
Description: get the struct for this entry
Parameter:  
@ptr:    the &struct list_head pointer.
@type:   the type of the struct this is embedded in.
@member: the name of the list_struct within the struct.

Author: SA12226114(Xin Zhu), SA12226139(Dan Shu)
Date: 2012-12-20
******************************************************************/
#define list_entry(ptr, type, member) \
    container_of(ptr, type, member)


/*****************************************************************
Function Name: list_for_each
Description: iterate over a list
Parameter:  
@pos:    the &struct list_head to use as a loop counter.
@head:   the head for your list.


Author: SA12226114(Xin Zhu), SA12226139(Dan Shu)
Date: 2012-12-20
******************************************************************/
#define list_for_each(pos, head) \
    for (pos = (head)->next, prefetch(pos->next); pos != (head); \
        pos = pos->next, prefetch(pos->next))




